package mcjunkin;
import java.util.*;
import java.io.*;
import java.math.*;
import java.security.*;

/**
	This encapsulates a file or folder in the system.
*/

public class Match{
	
	//the underlying file
	protected File file;
	
	//the MatchFolder that contains this file, or null for the parent
	protected MatchFolder parent;
	
	//the data about this file we store for convenience
	protected ArrayList<Match> matches;

	/** Constructs a matchfile on top of the underlying file. */
	public Match(File f, MatchFolder p) throws IOException, 
		NoSuchAlgorithmException{
		file = f;
		parent = p;
		if(p != null) p.addChild(this);
		matches = null;
	}

	/** Retreives a reference to the file */
	public File getFile(){
		return file;
	}

	/** Retreives a reference to the parent */
	public MatchFolder getParent(){
		return parent;
	}

	/** Adds a match */
	public void addMatch(Match m){
		if(matches == null) matches = new ArrayList<Match>();
		//if the match is already here, do not add it
		//for(int i=0; i < matches.size(); i++)
		//	if(matches.get(i).getFile().getAbsolutePath().equals(
		//		m.getFile().getAbsolutePath())) return ;
		matches.add(m);
	}

	/** Gets a match */
	public Match getMatch(int i){
		if(matches == null) return null;
		return matches.get(i);
	}

	/** Gets a match */
	public int getMatchCount(){
		if(matches == null) return 0;
		return matches.size();
	}

	public String toString(){
		return file.toString();
	}

}
